﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace VRacer.Packets
{
    public class LoginPacket : PlayerPacket
    {
        private int _version = 1;
        private string _name = "Player01";

        public LoginPacket()
            : base(PacketType.Login)
        {
            Length += 4;
        }

        public LoginPacket(WelcomePacket welcomePacket)
            : this()
        {
            _id = welcomePacket.ID;
        }

        public override int Length
        {
            get
            {
                int length = base.Length;
                length += UTF8Encoding.UTF8.GetByteCount(_name);

                return length;
            }
        }

        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        public int Version
        {
            get { return _version; }
            set { _version = value; }
        }

        public override void Read(System.IO.BinaryReader reader)
        {
            base.Read(reader);

            _version = reader.ReadInt32();
            _id = reader.ReadInt32();
            _name = reader.ReadString();
        }

        public override void Write(System.IO.BinaryWriter writer)
        {
            base.Write(writer);

            writer.Write(_version);
            writer.Write(_id);
            writer.Write(_name);
        }
    }
}
